$(function () {
    layui.use(['jquery', 'table'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        //渲染表格
        table.render({
            elem: "#moderatorTable",//渲染的表格的id
            url: "/bbs/getModeratorList.action",//请求后台的接口
            cols: [[//表头
                {type:'numbers',title:'编号',width:150,align:'center'},
                {field:'u_id',title:'版主ID',width:230,align:'center'},
                {field:'u_name',title:'版主姓名', width:230,align:'center'},
                {field:'b_id',title:'版块ID',width:230,align:'center'},
                {field:'b_title',title:'版块名称',width:230,align:'center'},
                {title:'操作',toolbar:'#userOperation',width:170,align:'center'},
            ]],
            page: false//是否开启分页
        });

        //表格的重载
        function reloadModeratorTable(){
            table.reload("moderatorTable",{
                where:{
                    u_id:$("u_id").val(),
                    u_name:$("u_name").val(),
                    b_id:$("b_id").val(),
                    b_title:$("b_title").val(),
                }
            },'data');
        }

        //监听表格的工具栏的事件
        table.on('tool(moderatorTable)',function (obj) {
            var data = obj.data;
            if(obj.event == 'removeModerator'){
                alert("删除");
                removeModerator(data.u_id, data.b_id);
                //changeUserType(data.u_id);
            }
        });

        //删除公告
        function removeModerator(u_id, b_id){
            $.ajax({
                url:"/bbs/removeModerator.action",
                type:"POST",
                data:{'u_id':u_id,'b_id':b_id},
                dataType:'JSON',
                cache:false,
                success:function (data) {
                    if(data.code==200){
                        alert("删除成功!");
                        //重载表格
                        reloadModeratorTable();
                    }else{
                        alert(data.msg);
                    }
                } ,
                error:function () {
                    alert("删除失败.")
                }
            });
        };
    });
})
